package com.longcai.service.impl.homepage;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.longcai.bean.ApiResult;
import com.longcai.entity.company.ClyjContext;
import com.longcai.mapper.homepage.ClyjContextMapper;
import com.longcai.service.homepage.ClyjContextService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author LWK
 * @since 2019-04-08
 */
@Service
public class ClyjContextServiceImpl extends ServiceImpl<ClyjContextMapper, ClyjContext> implements ClyjContextService {

    private static final Logger logger = LoggerFactory.getLogger(ClyjContextServiceImpl.class);
    @Autowired
    private ClyjContextMapper contextMapper;

    @Override
    public List<ClyjContext> listByBrandId(String id) {
        QueryWrapper<ClyjContext> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        List<ClyjContext> clyjContextList = this.contextMapper.selectList(queryWrapper);
        return clyjContextList;
    }

    /**
     * 新增
     *
     * @param contexts
     * @return
     */
    @Override
    public ClyjContext insertType(ClyjContext contexts) {
        try {
            ClyjContext context = contexts;
            context.setId(UUID.randomUUID().toString().replace("-", ""));
            context.setType("");
            context.setStatus("0");
            context.setCreateTime(new Date());
            context.setUpdateTime(new Date());
            context.setContent("");
            this.contextMapper.insert(context);
            logger.debug("新增成功", context.getId());

            return context;
        } catch (Exception e) {
            e.getMessage();
            e.printStackTrace();
        }
        return null;
    }


    /**
     * 删除
     *
     * @param id
     */
    @Override
    public void deleteType(String id) {
        try {
            QueryWrapper<ClyjContext> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id", id);
            this.contextMapper.delete(queryWrapper);
        } catch (Exception e) {
            e.printStackTrace();
            e.getMessage();
        }

    }

}
